<?php


namespace App\Services;

use App\Services\OrderPayService;

class CreditPay
{
    public static function doPay($params = [])
    {
        // 构建扣除参数
        $deductionParams = [
            'member_id' => $params['member_id'],
            'change_value' => $params['amount'],
            'operator' => 2,
            'operator_id' =>  $params['operator_id'] ?: 0,
            'remark' => '消费减少',
            'relation' => $params['order_sn']
        ];
        
        $result = (new OrderPayService())->deductionCB($deductionParams);
        
        if ($result === true) {
            return true;
        } else {
            \Log::error('[CreditPay] 茶包支付失败', [
                'order_sn' => $params['order_sn'] ?? null,
                'member_id' => $params['member_id'] ?? null
            ]);
            return false;
        }
    }
    
    public static function doPay2($params = [])
    {
        // 构建扣除参数
        $deductionParams = [
            'member_id' => $params['member_id'],
            'change_value' => $params['amount'],
            'operator' => 2,
            'operator_id' =>  $params['operator_id'] ?: 0,
            'remark' => '消费减少',
            'relation' => $params['order_sn']
        ];
        
        $result = (new OrderPayService())->deductionMYL($deductionParams);

        if ($result === true) {
            return true;
        } else {
            \Log::error('[CreditPay] 沐浴露支付失败', [
                'order_sn' => $params['order_sn'] ?? null,
                'member_id' => $params['member_id'] ?? null
            ]);
            return false;
        }
    }


    public static function doPay3($params = [])
    {
        // 构建扣除参数
        $deductionParams = [
            'member_id' => $params['member_id'],
            'change_value' => $params['amount'],
            'operator' => 2,
            'operator_id' =>  $params['operator_id'] ?: 0,
            'remark' => '消费减少',
            'relation' => $params['order_sn']
        ];
        
        $result = (new OrderPayService())->deductionQuota($deductionParams);

        if ($result === true) {
            return true;
        } else {
            \Log::error('[CreditPay] 额度支付失败', [
                'order_sn' => $params['order_sn'] ?? null,
                'member_id' => $params['member_id'] ?? null
            ]);
            return false;
        }
    }

}